package apirequest;

import util.UrlUtil;
import java.util.Map;

/**
 * @author liangyaqian
 */
public class ApiRequest {
    private String baseUrl;
    private String appId;
    private long timeStamp;
    private String token;


    public ApiRequest(String baseUrl, String appID, long timeStamp, String token) {
        this.baseUrl = baseUrl;
        this.appId = appID;
        this.timeStamp = timeStamp;
        this.token = token;
    }

    public static ApiRequest buildFromUrl(String fullUrl) {

        UrlUtil.UrlEntity urlEntity = UrlUtil.parse(fullUrl);
        Map<String,String> params = urlEntity.params;
        String appId = params.get("appId");
        long timestamp = Long.valueOf(params.get("timestamp"));
        String token = params.get("token");
        return new ApiRequest(urlEntity.baseUrl, appId, timestamp, token);
    }


    public String getBaseUrl() {
        return baseUrl;
    }

    public String getAppId() {
        return appId;
    }

    public long getTimeStamp() {
        return timeStamp;
    }

    public String getToken() {
        return token;
    }
}
